# Modelsim TCL Do file.
# Pulse Width Modulation Core simulation stimulus file.

# Clear previous forces and wave window
restart -force -nowave

# Add waves to simulator waveform window
add wave -divider -height 10 External
add wave Clk
add wave Rst
add wave DivReset
add wave -radix hexadecimal DivFactor
add wave PwmReset
add wave InverseEn
add wave OutEnable
add wave -radix hexadecimal PulseLen
add wave -radix hexadecimal PeriodLen
add wave PwmOut
add wave PwmDone

# Internal Waves
add wave -divider -height 10 Internal
add wave -radix hexadecimal PWMCore/PwmClkEn
add wave -radix hexadecimal PWMCore/DivCounter
add wave -radix hexadecimal PWMCore/PulseLenActiveReg
add wave -radix hexadecimal PWMCore/PeriodLenActiveReg
add wave -radix hexadecimal PWMCore/PWMCounter
add wave -radix hexadecimal PWMCore/PulseMatch
add wave -radix hexadecimal PWMCore/PwmOutReg
add wave -radix hexadecimal PWMCore/PeriodMatch
add wave -radix hexadecimal PWMCore/PwmCoreReset


# Configure waveform window
configure wave -namecolwidth 205
configure wave -valuecolwidth 100
configure wave -justifyvalue left
configure wave -signalnamewidth 0
configure wave -snapdistance 10
configure wave -datasetprefix 0
configure wave -rowmargin 4
configure wave -childrowmargin 2
configure wave -gridoffset 0
configure wave -gridperiod 10000
configure wave -griddelta 40
configure wave -timeline 1
configure wave -timelineunits ns


# Init control and stimulus signals
force Clk 0 0ns
force DivReset 0 0ns
force DivFactor 16'h0 0ns
force PwmReset 0 0ns
force InverseEn 0 0ns
force OutEnable 0 0ns
force PulseLen 32'h0 0ns
force PeriodLen 32'h0 0ns

# Generate Reset and Clock
force Rst 0 0ns, 1 10ns, 0 20ns
run 20.5ns
force Clk 1 0ns, 0 {0.25ns} -r 0.5ns


# Apply control signals
force -deposit InverseEn 0 5ns
force -deposit OutEnable 1 5ns
force -deposit OutEnable 1 5ns
force -deposit DivFactor 16'h9 5ns

run 11.5ns

# Apply stimulus signals
### Verification of general PWM Core functionality ###
# Set Period = 10 (9+1), Set Pulse = 10 - 100% Duty Cycle
force -deposit PulseLen 32'hA 16.5ns
force -deposit PeriodLen 32'h9 16.5ns
# Set Pulse = 0 - change to 0% DC
force -deposit PulseLen 32'h0 60ns
# Set Pulse = 1 - change to 10% DC
force -deposit PulseLen 32'h1 110ns
# Set Pulse = 2 - change to 20% DC
force -deposit PulseLen 32'h2 160ns

### Verification of PWM Core Reset functionality ###
# Set new data - Period = 30 (29+1), Pulse = 19
force -deposit PulseLen 32'h19 217.5ns
force -deposit PeriodLen 32'h29 217.5ns
# Apply new values before resettin PWM Core - Period = 10 (9+1), Pulse = 0 -> 0% Duty Cycle
force -deposit PulseLen 32'h0 300ns
force -deposit PeriodLen 32'h9 300ns
# Generate PwmReset (Reset PWM Core) strobe pulse
force -deposit PwmReset 1 317.1ns
force -deposit PwmReset 0 317.6ns

### General PWM COre functionality ###
# Set Pulse = 3 - change to 30% DC
force -deposit PulseLen 32'h3 360ns
force -deposit PulseLen 32'h4 410ns
force -deposit PulseLen 32'h5 460ns
force -deposit PulseLen 32'h6 510ns
force -deposit PulseLen 32'h7 560ns
force -deposit PulseLen 32'h8 610ns
# Set Pulse = 9 - change to 90% DC
force -deposit PulseLen 32'h9 660ns

### Verification of Integer Clock divider Reset functionality ###
# Reset integer clock divider
force -deposit DivReset 1 770.6ns
force -deposit DivReset 0 771.1ns

run 800 ns
WaveRestoreZoom {0 ns} {800 ns}